package com.wenwei.sharebox.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wenwei.sharebox.R;
import com.wenwei.sharebox.bean.UserShareBean;
import com.wenwei.sharebox.utils.RogerDateUtils;
import com.wenwei.sharebox.utils.TimeTextView;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/7.
 */
public class ShareZuAdapter extends RecyclerView.Adapter<ShareZuAdapter.MyViewHolder> {
    private CallBack mCallBack;
    private Context mContext;
    public interface CallBack {
        void onZuItemClick(UserShareBean.DataBean bean);

        void onZuReturnMoney(UserShareBean.DataBean bean);
    }

    private long currentTime;

    private List<UserShareBean.DataBean> mList;

    public void setShareDataList(List<UserShareBean.DataBean> list,long time) {
        this.mList = list;
        this.currentTime = time;
    }

    public ShareZuAdapter(CallBack callBack) {
        this.mCallBack = callBack;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mContext = parent.getContext();
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_user_zu, null));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        try{
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mCallBack.onZuItemClick(mList.get(position));
                }
            });
//            holder.returnMoney.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    mCallBack.onZuReturnMoney(mList.get(position));
//                }
//            });
            holder.itemName.setText(mList.get(position).getShopName());
            Glide.with(mContext).load(mList.get(position).getShopImg()).into(holder.itemShareImg);
            holder.itemPrice.setText(mList.get(position).getPayTotal()+"积分/小时");
            holder.timeTv.setTimes(RogerDateUtils.getTimeCha(currentTime,mList.get(position).getCreatedTime()));
        }catch (Exception e){}

    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.item_share_img)
        ImageView itemShareImg;
        @Bind(R.id.item_name)
        TextView itemName;
        @Bind(R.id.item_price)
        TextView itemPrice;
        @Bind(R.id.return_money)
        TextView returnMoney;
        @Bind(R.id.time_tv)
        TimeTextView timeTv;

        public MyViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
